package com.haiheng.videodoorbell.widget.webview

import android.graphics.Bitmap
import android.text.TextUtils
import com.haiheng.library.log.LogUtils
import com.tencent.smtt.sdk.WebView
import com.tencent.smtt.sdk.WebViewClient

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2022/3/25 0025
 * @Version: 1.0
 */
class MyX5WebViewClient @JvmOverloads constructor(
    ix5WebPageView: IX5WebPageView)  : WebViewClient() {

    val mIWebPageView:IX5WebPageView

    init {
        this.mIWebPageView = ix5WebPageView
    }

    override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
        //这里可以对特殊scheme进行拦截处理
        LogUtils.e("webview ---shouldOverrideUrlLoading-url:" + url);
        //要返回true否则内核会继续处理
        if (TextUtils.isEmpty(url)){
            return false
        }else{
            return mIWebPageView.isOpenThirdApp(url)
        }
    }


    override fun onReceivedError(p0: WebView?, p1: Int, p2: String?, p3: String?) {
        super.onReceivedError(p0, p1, p2, p3)
    }

    override fun onPageFinished(p0: WebView?, p1: String?) {
        super.onPageFinished(p0, p1)
        mIWebPageView.onPageFinished(p0,p1)
    }

    override fun onPageStarted(p0: WebView?, p1: String?, p2: Bitmap?) {
        super.onPageStarted(p0, p1, p2)
    }
}